<?php

namespace app\admin\controller;

use app\admin\logic\IndexLogic;

/**
 * Created by PhpStorm.
 * User: tyll
 * Date: 2019/09/16
 * Time: 16:58
 */
class Index extends Base
{
    public function __construct()
    {
        parent::__construct();
        $this->i_logic = new IndexLogic();
    }

    /**
     * 获取用户信息
     * @return \think\response\Json
     */
    public function ajax_get_info()
    {
        $params = input();
        $r = $this->check_admin_token($params);
        if ($r['code'] != 1) {
            return json($r);
        }

        //检查后台用户规则
        $r = $this->i_logic->check_admin_rule('id,openid,role,username,status,enable');
        if (!$r['code']) {
            return json($r);
        }
        $detail = $r['data']['detail'];

        //获取权限
        $maps = [];
        $maps[] = ['openid', '=', $detail['openid']];
        $up_detail = model('user_power')->get_detail($maps, 'id,admin_power');
        $detail['admin_power'] = !empty($up_detail) ? json_decode($up_detail['admin_power'], true) : [];

        $data['admin_info'] = $detail;
        return json($this->i_logic->get_response(1, 'OK', $data));
    }
}
